clear all
close all

%number of sample paths
Nsample = 1000;


%parameter values
zeta  = .35;  
T = 50;
freq = 4; %views loss/gain this many years
ploss = .5;   %probability of loss versus gain.

%vector of potential losses
%potloss = [1:freq:T]';
ploss = .5/freq;
potloss = [1:1:T]';
Npotloss = size(potloss,1);
ps = zeros(T,Nsample);


Xs = rand(Npotloss,Nsample);
losses = Xs<ploss;



 for k = 1:Nsample
     loss = losses(:,k); %which potential losses are losses
     loss = potloss.*loss;
     loss = nonzeros(loss);   
     if isempty(loss)
         ps(:,k) = ones(size(1,T));
     else
         ps(:,k) = featureslong(zeta,T,loss)/2;
     end

 end
 
 
 paverage = sum(ps,2)/Nsample;
 figure(1)
 plot([1:T],paverage)
 save paverage
    
     
   



